load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("@rules_license//rules:license.bzl", "license")

package(
    default_applicable_licenses = [":license"],
)

exports_files(["LICENSE"])

license(
    name = "license",
    package_name = "open62541pp",
    license_kinds = ["@rules_license//licenses/spdx:MPL-2.0"],
    license_text = "LICENSE",
    package_url = "https://github.com/open62541pp/open62541pp",
)

expand_template(
    name = "config_hpp",
    template = "include/open62541pp/config.hpp.in",
    substitutions = {
        "@PROJECT_NAME@": "open62541pp",
        "@VERSION@": "0.20.0",
        "@PROJECT_VERSION_MAJOR@": "0",
        "@PROJECT_VERSION_MINOR@": "20",
        "@PROJECT_VERSION_PATCH@": "0",

        "#cmakedefine UAPP_ENABLE_NODESETLOADER": "/* #undef UAPP_ENABLE_NODESETLOADER */",
    },
    out = "include_generated/open62541pp/config.hpp",
)

cc_library(
    name = "open62541pp_config_header",
    hdrs = [":config_hpp"],
    includes = ["include_generated"],
)

cc_library(
    name = "open62541pp",
    hdrs = glob([
        "include/open62541pp/**/*.hpp",
        "include/open62541pp/detail/open62541/*.h",
    ]),
    srcs = glob(["src/**/*.cpp"]),
    deps = [
        ":open62541pp_config_header",
        "@open62541//:open62541",
    ],
    includes = ["include"],
    visibility = ["//visibility:public"],
)

cc_test(
    name = "open62541pp_tests",
    srcs = glob(["tests/*.cpp", "tests/helper/*.hpp"]),
    deps = [
        "@open62541pp//:open62541pp",
        "@open62541//:open62541",
        "@catch2//:catch2_main",
        "@boringssl//:crypto"
    ],
)
